import { h, Component } from 'preact';
import classNames from 'classnames';
import s from './WinRecord.scss';
import MessageBox from '~/components/Message';
import moment from 'moment';
import store from '~/utils/common/store';
import history from '~/core/history';
import { connect } from 'preact-redux';
import { getDrawPrizeRecordAction } from '~/actions/user';
class WinRecord extends Component {
	constructor(props,context) {
		super(props,context);
	}
	componentWillMount() {
		const {dispatch} = this.props;
		dispatch(getDrawPrizeRecordAction()).catch(err => {
			MessageBox.show({ title: err.errorMsg || '系统错误'});
		});
	}
	onClick = (detailId) => () => {
		const {dispatch} = this.props;
		dispatch({type:'openAddress',payload: {detailId}});
	}
	onView = (detailId) => () => {
		const {dispatch} = this.props;
		dispatch(() => {
			dispatch({type:'detailId',payload: {detailId}});
			return Promise.resolve();
		}).then(() => {
			history.push('/ecard');
		});
	}
	render() {
		const { winrecord } = this.props;
		const { record, recommendScore } = winrecord || {};
		const { onClick, onView } = this;
		return (
			<div className={s.table}>
				<div className={s.header}>
					已获得积分
					<span>
						{recommendScore || 0}分
					</span>
				</div>
				<div className={s.body}>
					{(record || []).map((item, index)=> (<div className={s.infoBox}>
						<div className={s.dotBox}>
							<span className={s.dot}>
							</span>
						</div>
						<div className={s.dateBox}>{moment(item.createTime).format('MM.DD')}</div>
						<div className={s.detailBox}>
							<div>{item.prizeName}</div>
							<div>收货信息：张三，13555555555，{item.address}</div>
							{item.prizeType === 1 && item.status === 4 ? <div><a onClick={onClick(item.detailId)} className={s.button}>去填地址</a></div> : null}
							{item.prizeType === 5  ? <div><a onClick={onView(item.detailId)} className={s.button}>查看</a></div> : null}
						</div>
					</div>))}

					{/*<div className={s.infoBox}>
						<div className={s.dotBox}>
							<span className={s.dot}>
							</span>
						</div>
						<div className={s.dateBox}>02.05</div>
						<div className={s.detailBox}>
							<div>现金红包8.88</div>
						</div>
					</div>
					<div className={s.infoBox}>
						<div className={s.dotBox}>
							<span className={s.dot}>
							</span>
						</div>
						<div className={s.dateBox}>02.05</div>
						<div className={s.detailBox}>
							<div>蛋白粉450g</div>
							<div><a className={s.button}>去填地址</a></div>
						</div>
					</div>
					<div className={s.infoBox}>
						<div className={s.dotBox}>
							<span className={s.dot}>
							</span>
						</div>
						<div className={s.dateBox}>02.05</div>
						<div className={s.detailBox}>
							<div>蛋白粉450g</div>
							<div><a className={s.button}>去填地址</a></div>
						</div>
					</div>
					<div className={s.infoBox}>
						<div className={s.dotBox}>
							<span className={s.dot}>
							</span>
						</div>
						<div className={s.dateBox}>02.05</div>
						<div className={s.detailBox}>
							<div>蛋白粉450g</div>
							<div><a className={s.button}>去填地址</a></div>
						</div>
					</div>
					<div className={s.infoBox}>
						<div className={s.dotBox}>
							<span className={s.dot}>
							</span>
						</div>
						<div className={s.dateBox}>02.05</div>
						<div className={s.detailBox}>
							<div>蛋白粉450g</div>
							<div><a className={s.button}>去填地址</a></div>
						</div>
					</div>
					<div className={s.infoBox}>
						<div className={s.dotBox}>
							<span className={s.dot}>
							</span>
						</div>
						<div className={s.dateBox}>02.05</div>
						<div className={s.detailBox}>
							<div>蛋白粉450g</div>
							<div><a className={s.button}>去填地址</a></div>
						</div>
					</div>
					<div className={s.infoBox}>
						<div className={s.dotBox}>
							<span className={s.dot}>
							</span>
						</div>
						<div className={s.dateBox}>02.05</div>
						<div className={s.detailBox}>
							<div>蛋白粉450g</div>
							<div><a className={s.button}>去填地址</a></div>
						</div>
					</div>
					<div className={s.infoBox}>
						<div className={s.dotBox}>
							<span className={s.dot}>
							</span>
						</div>
						<div className={s.dateBox}>02.05</div>
						<div className={s.detailBox}>
							<div>蛋白粉450g</div>
							<div><a className={s.button}>去填地址</a></div>
						</div>
					</div>*/}
				</div>

				<div className={s.footer}></div>
			</div>
		);
	}
}

function mapStateToProps(state) {
	return state;
}

export default connect(mapStateToProps)(WinRecord);

